import java.math.BigInteger;

public class Solution8 {
    public int myAtoi(String s) {
        s = s.trim();
        if (s.length() == 0)
            return 0;
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i) > '9' || s.charAt(i) < '0') {
                s = s.substring(0, i);
                break;
            }
        }
        /*char c = s.charAt(0);
        if ((c > '9' || c < '0') && (c != '+' || c != '-'))
            return 0;*/
        try {
            return Integer.parseInt(s);
        } catch (Exception e) {
            try {
                BigInteger a = new BigInteger(s);
                if (a.compareTo(new BigInteger("0")) < 0) {
                    return Integer.MIN_VALUE;
                } else {
                    return Integer.MAX_VALUE;
                }
            } catch (Exception e1) {
                return 0;
            }
        }

    }
}
